/*
 * ChartWindow.java
 *
 * Created on __DATE__, __TIME__
 */

package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.statistics.HistogramDataset;
import org.jfree.data.statistics.HistogramType;

import core.Calculator;
import core.Category;
import core.Core;
import core.DateCalendar;
import core.UserEntry;

/**
 * 
 * @author __USER__
 */
public class ChartWindow extends javax.swing.JFrame {

	private Core core = null;
	private ChartPanel chartPanel = null;
	private PrincipalWindow parent;

	/** Creates new form ChartWindow */
	public ChartWindow(PrincipalWindow parent, boolean modal) {
		// super(parent, modal);
		this.parent = parent;
		core = Core.get();
		initComponents();

		configure();

		DefaultTableModel model1 = (DefaultTableModel) jTable1.getModel();
		DefaultTableModel model2 = (DefaultTableModel) jTable2.getModel();
		jTable1.setColumnSelectionAllowed(false);
		jTable1.getTableHeader().setReorderingAllowed(false);
		jTable2.setColumnSelectionAllowed(false);
		jTable2.getTableHeader().setReorderingAllowed(false);
		model1.setColumnCount(0);
		model1.addColumn("Category");
		model1.addColumn("Value");
		model2.setColumnCount(0);
		model2.addColumn("Category");
		model2.addColumn("Value");

		UpdatePieChart(Calculator.beginOf(1950, 1), Calculator.beginOf(2100, 1));
	}

	public void UpdatePieChart(Date since, Date until) {
		monthPanel.add(chartPanel);
		DebitPanelChart.setLayout(new BorderLayout());
		DebitPanelChart.add(createChartPie(core.getCalculator().getRatiosPos(
				since, until)));
		creditPanelChart.setLayout(new BorderLayout());
		creditPanelChart.add(createChartPie(core.getCalculator().getRatiosNeg(
				since, until)));

		DecimalFormat df = new DecimalFormat("0.00\u20ac");
		DefaultTableModel model1 = (DefaultTableModel) jTable1.getModel();
		DefaultTableModel model2 = (DefaultTableModel) jTable2.getModel();
		model1.setNumRows(0);
		model2.setNumRows(0);
		List<UserEntry> entries = core.getEntriesBetween(since, until);
		List<Category> categories = core.getCategories();
		Iterator<Category> i = categories.iterator();
		float balance = core.getCalculator().balancePosOf(entries, 0);
		if (balance > 0)
			model1.addRow(new Object[] { "None", df.format(balance) });
		balance = core.getCalculator().balanceNegOf(entries, 0);
		if (balance > 0)
			model2.addRow(new Object[] { "None", df.format(balance) });
		while (i.hasNext()) {
			Category c = i.next();
			balance = core.getCalculator().balancePosOf(entries, c.getId());
			if (balance > 0)
				model1.addRow(new Object[] { c.getName(), df.format(balance) });
			balance = core.getCalculator().balanceNegOf(entries, c.getId());
			if (balance > 0)
				model2.addRow(new Object[] { c.getName(), df.format(balance) });
		}

		for (int j = 0; j < 5; ++j) {
			model1.addRow(new Object[] {});
			model2.addRow(new Object[] {});
		}
	}

	public void configure() {
		String[] years = new String[20];
		int firstDate = 2006;
		for (int i = 0; i < 20; i++) {
			years[i] = Integer.toString(firstDate++);
		}
		yearBox.setModel(new DefaultComboBoxModel(years));
		Date date = new Date();
		yearBox.getModel().setSelectedItem(
				Integer.toString(date.getYear() + 1900));

		jComboBox1.removeAllItems();
		jComboBox1.addItem("All");
		jComboBox1.addItem("None");
		List<Category> categories = core.getCategories();
		Iterator<Category> i = categories.iterator();
		while (i.hasNext()){
			Category cur = i.next();
			jComboBox1.addItem(cur.getName());
		}
	}

	public void createDualAxis(int cat) {
		final CategoryDataset dataset1 = createDataset1(cat);
		Date d1 = new Date();
		final JFreeChart chart = ChartFactory.createBarChart3D("Chart",
				"Months", "Amount", dataset1, PlotOrientation.VERTICAL, true,
				true, false);
		chart.setBackgroundPaint(new Color(236, 242, 251));

		// get a reference to the plot for further customisation...
		final CategoryPlot plot = chart.getCategoryPlot();
		plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

		final CategoryItemRenderer renderer1 = plot.getRenderer();
		renderer1.setSeriesPaint(0, new Color(201, 201, 255));
		renderer1.setSeriesPaint(1, new Color(209, 107, 158));
		plot.mapDatasetToRangeAxis(1, 1);
		plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

		// add the chart to a panel...
		this.chartPanel = new ChartPanel(chart);
		monthPanel.setLayout(new BorderLayout());
		Date d2 = new Date();
		System.out.println("time" + (d2.getTime() - d1.getTime()));
	}

	private CategoryDataset createDataset1(int cat) {
		final String series1 = "Credit";
		final String series2 = "Debit";

		// create the dataset...
		final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		int year;
		if (yearBox.getModel().getSelectedItem().equals(null)) {
			year = new Date().getYear() + 1900;
		} else {
			year = Integer.parseInt((String) yearBox.getModel()
					.getSelectedItem());
		}
		DateCalendar date = new DateCalendar(1, 2011);

		if (cat == -1)
			for (int i = 0; i < 12; i++) {
				dataset.addValue(
						core.getCalculator().getBalancePos(
								Calculator.beginOf(year, i),
								Calculator.endOf(year, i)), series1,
						date.getMonth(i));
				dataset.addValue(
						core.getCalculator().getBalanceNeg(
								Calculator.beginOf(year, i),
								Calculator.endOf(year, i)), series2,
						date.getMonth(i));
			}
		else {
			for (int i = 0; i < 12; i++) {
				List<UserEntry> entriesCat = core.getEntriesOfBetween(cat,
						Calculator.beginOf(year, i), Calculator.endOf(year, i));
				dataset.addValue(
						core.getCalculator().balancePosOf(entriesCat, cat),
						series1, date.getMonth(i));
				dataset.addValue(
						core.getCalculator().balanceNegOf(entriesCat, cat),
						series2, date.getMonth(i));
			}
		}
		return dataset;
	}

	public void createChartHisto() {
		double[] value = new double[100];
		Random generator = new Random();
		for (int i = 1; i < 100; i++) {
			value[i] = generator.nextDouble();
		}
		int number = 10;
		HistogramDataset dataset = new HistogramDataset();
		dataset.setType(HistogramType.RELATIVE_FREQUENCY);
		dataset.addSeries("Histogram", value, number);
		String plotTitle = "Histogram";
		String xaxis = "number";
		String yaxis = "value";
		PlotOrientation orientation = PlotOrientation.VERTICAL;
		boolean show = false;
		boolean toolTips = false;
		boolean urls = false;
		JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis,
				yaxis, dataset, orientation, show, toolTips, urls);
		int width = 500;
		int height = 300;
		monthPanel.setLayout(new BorderLayout());
		ChartPanel chartPanel = new ChartPanel(chart);
		monthPanel.add(chartPanel);
	}

	public ChartPanel createChartPie(float[] ratios) {
		Core core = Core.get();
		List<Category> categories = core.getCategories();

		DefaultPieDataset pieDataset = new DefaultPieDataset();
		if (ratios[0] > 0)
			pieDataset.setValue("None", new Integer((int) (ratios[0] * 100)));
		for (int i = 1; i < ratios.length; ++i)
			if (ratios[i] > 0) {
				System.out.println("OK : " + categories.get(i - 1).getName()
						+ ratios[i]);
				pieDataset.setValue(categories.get(i - 1).getName(),
						new Integer((int) (ratios[i] * 100)));
			}
		JFreeChart chart = ChartFactory.createPieChart("Category Pie Chart",
				pieDataset, true, true, false);
		ChartPanel chartPanel = new ChartPanel(chart);
		return chartPanel;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel1 = new javax.swing.JPanel();
		yearBox = new javax.swing.JComboBox();
		jLabel1 = new javax.swing.JLabel();
		monthPanel = new javax.swing.JPanel();
		jLabel4 = new javax.swing.JLabel();
		jComboBox1 = new javax.swing.JComboBox();
		jPanel2 = new javax.swing.JPanel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jTabbedPane2 = new javax.swing.JTabbedPane();
		DebitPanel = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();
		DebitPanelChart = new javax.swing.JPanel();
		jPanel4 = new javax.swing.JPanel();
		jScrollPane2 = new javax.swing.JScrollPane();
		jTable2 = new javax.swing.JTable();
		creditPanelChart = new javax.swing.JPanel();
		jLabel5 = new javax.swing.JLabel();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Charts");

		jTabbedPane1.setToolTipText("");

		jPanel1.setToolTipText("");

		yearBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Item 1", "Item 2", "Item 3", "Item 4" }));
		yearBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				calYearChanged(evt);
			}
		});

		jLabel1.setText("Year:");

		javax.swing.GroupLayout monthPanelLayout = new javax.swing.GroupLayout(
				monthPanel);
		monthPanel.setLayout(monthPanelLayout);
		monthPanelLayout.setHorizontalGroup(monthPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 763, Short.MAX_VALUE));
		monthPanelLayout.setVerticalGroup(monthPanelLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 371,
				Short.MAX_VALUE));

		jLabel4.setText("Category");

		jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Item 1", "Item 2", "Item 3", "Item 4" }));

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						jPanel1Layout
								.createSequentialGroup()
								.addContainerGap()
								.addComponent(jLabel1)
								.addGap(37, 37, 37)
								.addComponent(yearBox,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGap(44, 44, 44)
								.addComponent(jLabel4)
								.addGap(33, 33, 33)
								.addComponent(jComboBox1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(443, Short.MAX_VALUE))
				.addComponent(monthPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(jLabel1)
														.addComponent(
																yearBox,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addGroup(
																jPanel1Layout
																		.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																		.addComponent(
																				jLabel4)
																		.addComponent(
																				jComboBox1,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addGap(39, 39, 39)
										.addComponent(
												monthPanel,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		jLabel1.getAccessibleContext().setAccessibleName("Year");

		jTabbedPane1.addTab("Debits and credits by month", jPanel1);

		jLabel2.setText("Start Date:");

		jLabel3.setText("End Date:");

		jTable1.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jScrollPane1.setViewportView(jTable1);

		javax.swing.GroupLayout DebitPanelChartLayout = new javax.swing.GroupLayout(
				DebitPanelChart);
		DebitPanelChart.setLayout(DebitPanelChartLayout);
		DebitPanelChartLayout.setHorizontalGroup(DebitPanelChartLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 722, Short.MAX_VALUE));
		DebitPanelChartLayout.setVerticalGroup(DebitPanelChartLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 227, Short.MAX_VALUE));

		javax.swing.GroupLayout DebitPanelLayout = new javax.swing.GroupLayout(
				DebitPanel);
		DebitPanel.setLayout(DebitPanelLayout);
		DebitPanelLayout
				.setHorizontalGroup(DebitPanelLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								DebitPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												DebitPanelLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																722,
																Short.MAX_VALUE)
														.addComponent(
																DebitPanelChart,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))
										.addContainerGap()));
		DebitPanelLayout.setVerticalGroup(DebitPanelLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				DebitPanelLayout
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPane1,
								javax.swing.GroupLayout.PREFERRED_SIZE, 104,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(18, 18, 18)
						.addComponent(DebitPanelChart,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));

		jTabbedPane2.addTab("Debit", DebitPanel);

		jTable2.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jScrollPane2.setViewportView(jTable2);

		javax.swing.GroupLayout creditPanelChartLayout = new javax.swing.GroupLayout(
				creditPanelChart);
		creditPanelChart.setLayout(creditPanelChartLayout);
		creditPanelChartLayout.setHorizontalGroup(creditPanelChartLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 722, Short.MAX_VALUE));
		creditPanelChartLayout.setVerticalGroup(creditPanelChartLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 227, Short.MAX_VALUE));

		javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(
				jPanel4);
		jPanel4.setLayout(jPanel4Layout);
		jPanel4Layout
				.setHorizontalGroup(jPanel4Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								jPanel4Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(
																creditPanelChart,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addComponent(
																jScrollPane2,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																722,
																Short.MAX_VALUE))
										.addContainerGap()));
		jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				jPanel4Layout
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPane2,
								javax.swing.GroupLayout.PREFERRED_SIZE, 104,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(18, 18, 18)
						.addComponent(creditPanelChart,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));

		jTabbedPane2.addTab("Credit", jPanel4);

		jLabel5.setText("jLabel5");
		jLabel5.setOpaque(true);

		jLabel6.setText("jLabel6");
		jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				callCalendar(evt);
			}
		});
		jLabel6.addKeyListener(new java.awt.event.KeyAdapter() {
			public void keyPressed(java.awt.event.KeyEvent evt) {
				jLabel6KeyPressed(evt);
			}
		});

		jLabel7.setText("jLabel7");

		jLabel8.setText("jLabel6");
		jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				callCalendar(evt);
			}
		});

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanel2Layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				jLabel2)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jLabel5,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				75,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jLabel6)
																		.addGap(64,
																				64,
																				64)
																		.addComponent(
																				jLabel3)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jLabel7,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				78,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jLabel8))
														.addComponent(
																jTabbedPane2,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																751,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
														.addComponent(jLabel3)
														.addComponent(jLabel5)
														.addComponent(jLabel7)
														.addComponent(jLabel6)
														.addComponent(jLabel8))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												11, Short.MAX_VALUE)
										.addComponent(
												jTabbedPane2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												392,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap()));

		jTabbedPane1.addTab("Details of debits and credits", jPanel2);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 768,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 475,
				Short.MAX_VALUE));

		jTabbedPane1.getAccessibleContext().setAccessibleName("ff");

		pack();
	}// </editor-fold>
		// GEN-END:initComponents

	private void callCalendar(java.awt.event.MouseEvent evt) {
		CalendarWindow calendar = new CalendarWindow(this.parent, true);
		calendar.setVisible(true);
		calendar.setAlwaysOnTop(true);
		System.err.println("Call calendar");
	}

	private void jLabel6KeyPressed(java.awt.event.KeyEvent evt) {
		// TODO add your handling code here:
	}

	private void calYearChanged(java.awt.event.ActionEvent evt) {
		int catId = (jComboBox1.getSelectedIndex() <= 1) ? jComboBox1
				.getSelectedIndex() - 1 : core.getCategories()
				.get(jComboBox1.getSelectedIndex() - 2).getId();

		System.out.println("year changed: " + catId);
		monthPanel.removeAll();
		System.gc();
		createDualAxis(catId);
		monthPanel.add(this.chartPanel);
		super.repaint();
	}

	/**
	 * @param args
	 *            the command line arguments
	 */

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JPanel DebitPanel;
	private javax.swing.JPanel DebitPanelChart;
	private javax.swing.JPanel creditPanelChart;
	private javax.swing.JComboBox jComboBox1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JTabbedPane jTabbedPane1;
	private javax.swing.JTabbedPane jTabbedPane2;
	private javax.swing.JTable jTable1;
	private javax.swing.JTable jTable2;
	private javax.swing.JPanel monthPanel;
	private javax.swing.JComboBox yearBox;
	// End of variables declaration//GEN-END:variables

}